//
//  SAboutusViewController.m
//  Gunz
//
//  Created by Joggy on 16/5/23.
//  Copyright © 2016年 NUPT. All rights reserved.
//

#import "SAboutusViewController.h"
#import "GZConst.h"
#import "MMTableViewCell.h"

@interface SAboutusViewController () <UITableViewDelegate, UITableViewDataSource> {
    
    UITableView *table;
    
}

@end

@implementation SAboutusViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self prepareForNav];
    [self prepareForLayout];
}

- (void)prepareForNav {
    [super prepareForNav];
    self.title = @"关于我们";
    //导航左按键
    UIImage *image = [UIImage imageNamed:@"all_back"];
    UIButton *leftBarButton = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBarButton.frame = CGRectMake(0, 0, image.size.width, image.size.height);
    leftBarButton.layer.position = CGPointMake(22, 22);
    [leftBarButton setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [leftBarButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarButton];
}

- (void)prepareForLayout {
    [super prepareForLayout];
    //头部图标和文字
    UIImageView *headImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 65, 65)];
    headImage.image = [UIImage imageNamed:@"插图2"];
    headImage.layer.cornerRadius = headImage.frame.size.width/2;
    headImage.layer.masksToBounds = true;
    headImage.layer.position = CGPointMake(screenWidth/2, 29 + headImage.frame.size.height/2);
    [self.view addSubview:headImage];
    UILabel *appName = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 42, 17)];
    appName.text = @"群智社";
    appName.textColor = [UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1];
    appName.font = [UIFont systemFontOfSize:14];
    appName.layer.position = CGPointMake(screenWidth/2, headImage.frame.origin.y + headImage.frame.size.height + appName.frame.size.height/2 + 9);
    [self.view addSubview:appName];
    //相关内容列表
    table = [[UITableView alloc] initWithFrame:CGRectMake(0, 150, screenWidth, 47*6) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.backgroundColor = [UIColor clearColor];
    table.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 10)];
    table.showsVerticalScrollIndicator = false;
    table.separatorStyle = UITableViewCellSelectionStyleBlue;
    table.separatorColor = [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1];
    table.tableFooterView = [[UIView alloc] init];
    [table registerClass:[MMTableViewCell class] forCellReuseIdentifier:@"SACell"];
    [self.view addSubview:table];
}

- (void)back {
    [self.navigationController popViewControllerAnimated:true];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma 代理方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 47;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MMTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SACell"];
    if(indexPath.row == 0) {
        cell.textLabel.text = @"当前版本";
        cell.infoLabel.text = @"V1.0";
        cell.backgroundColor = [UIColor colorWithRed:0.9765 green:0.9765 blue:0.9843 alpha:1];
        return cell;
    }
    else {
        cell.textLabel.text = @"联系方式";
        cell.infoLabel.text = @"400-1234-5678";
        cell.infoLabel.textColor = [UIColor colorWithRed:242/255.0 green:71/255.0 blue:59/255.0 alpha:1];
        cell.backgroundColor = [UIColor colorWithRed:0.9765 green:0.9765 blue:0.9843 alpha:1];
        return cell;
    }
}

@end
